package cn.dw.mm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.dw.mm.domain.Role;
import cn.dw.mm.service.RoleService;

@Controller
@RequestMapping("/role")
public class RoleController {
	
	@Autowired
	private RoleService roleService;
	
	@RequestMapping("/page")
	public String page() {
		return "role/list";
	}
	
	@RequestMapping("/add")
	public String add(Role role) {
		roleService.insertSelective(role);
		return "success";
	}
	
	@RequestMapping("/del")
	public String del(String ids) {
		String[] idList = ids.split(",");
		for (String id : idList) {
			Integer i = Integer.parseInt(id);
			roleService.deleteByPrimaryKey(i);
		}
//		roleService.deleteByPrimaryKey(id);
		return "success";
	}
	
	@RequestMapping("/query")
	@ResponseBody
	public Role query(Role role) {
		return roleService.selectByPrimaryKey(role.getId());
	}
	
	@RequestMapping("/mod")
	public String mod(Role role) {
		roleService.updateByPrimaryKeySelective(role);
		return "success";
	}
	
	@RequestMapping("/selectAll")
	@ResponseBody
    public List<Role> selectAll(Role role) {
    	return roleService.selectAll(role);
    }
}
